package cn.kgc.controller;

import cn.kgc.config.ZookeeperConnector;
import cn.kgc.config.ZookeeperLock;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author YC
 */
@RestController
@RequestMapping("/zookeeper")
@Api(tags = "Zookeeper测试接口")
@Slf4j
public class ZookeeperController {

    @RequestMapping("/getLock1")
    public String getLock1() {
        ZookeeperLock zooKeeperLock = new ZookeeperLock(
                ZookeeperConnector.zooKeeper,
                10000,
                "mylock",
                "/lock"
        );
        try {
            zooKeeperLock.lock();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return "SUCCESS";
    }

    @RequestMapping("/getLock2")
    public String getLock2() {
        ZookeeperLock zooKeeperLock = new ZookeeperLock(
                ZookeeperConnector.zooKeeper,
                10000,
                "mylock",
                "/lock"
        );
        try {
            zooKeeperLock.lock();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return "SUCCESS";
    }

}
